<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>批发客户管理</title>
		<link rel="stylesheet" href="__PEAR__/component/pear/css/pear.css" />
		<style>
		.layui-input{width:250px;}
		.layui-form-label{width:auto;}
		.layui-form-item .layui-input-inline{width: 250px;}
		</style>
	</head>
	<body class="pear-container">
		<div class="layui-card">
			<div class="layui-card-body">
				<form class="layui-form" action="">
					<div class="layui-form-item">
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">关键词</label>
							<div class="layui-input-inline">
								<input type="text" name="keyword" placeholder="请输入联系人/手机/公司名称" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">所属区域</label>
							<div class="layui-input-inline">
								<select name="areano" lay-verify="" lay-search>
									<option value="">请选择...</option>
									{volist name="areaList" id="vo"}
									<option value="{$vo['code_id']}">{$vo['code_name']}</option>
									{/volist}
								</select>
							</div>
						</div>
						<div class="layui-form-item layui-inline">
							<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="wslist-query">
								<i class="layui-icon layui-icon-search"></i>
								查询
							</button>
							<button type="reset" class="pear-btn pear-btn-md">
								<i class="layui-icon layui-icon-refresh"></i>
								重置
							</button>
						</div>
					</div>
				</form>
			</div>
		</div>
		<div class="layui-card">
			<div class="layui-card-body">
				<table id="wslist-table" lay-filter="wslist-table"></table>
			</div>
		</div>

		<script type="text/html" id="wslist-toolbar">
			<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
		        <i class="layui-icon layui-icon-add-1"></i>
		        新增
		    </button>
		    <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
		        <i class="layui-icon layui-icon-delete"></i>
		        删除
		    </button>
		</script>

		<script type="text/html" id="wslist-bar">
			<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></button>
		</script>

		<script type="text/html" id="wslist-enable">
			<input type="checkbox" name="enable" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="user-enable" checked = "{{ d.enable == 0 ? 'true' : 'false' }}">
		</script>

		<script type="text/html" id="wslist-createTime">
			{{layui.util.toDateString(d.createTime, 'yyyy-MM-dd')}}
		</script>

		<script src="__STATIC__/lib/layui/layui.js"></script>
		<script src="__PEAR__/component/pear/pear.js"></script>
		<script>
			layui.use(['table', 'form', 'jquery','common'], function() {
				let table = layui.table;
				let form = layui.form;
				let $ = layui.jquery;
				let common = layui.common;

				let MODULE_PATH = "/{$MODULE_NAME}/Wholesale/index/";
				let DATA_PATH = "/{$MODULE_NAME}/common/index/";

				let cols = [
					[	{
							type: 'checkbox'
						},
						{
							title: '批发客户编码',
							field: 'clients_no',
							align: 'center',
							width: 150
						},
						{
							title: '所属区域',
							field: 'areaname',
							align: 'center'
						},
						{
							title: '联系人',
							field: 'linkname',
							align: 'center',
							width: 200
						},
						{
							title: '手机号码',
							field: 'mobile',
							align: 'center',
							width: 200
						},
						{
							title: '联系电话',
							field: 'phone',
							align: 'center'
						},
						{
							title: '批发价格',
							field: 'type_name',
							align: 'center'
						},
						{
							title: '结算方式',
							field: 'balancename',
							align: 'center'
						},
						{
							title: '业务员',
							field: 'oper_name',
							align: 'center'
						},
						{
							title: '所属门店',
							field: 'branchname',
							align: 'center'
						},
						{
							title: '操作',
							toolbar: '#wslist-bar',
							align: 'center',
							width: 150
						}
					]
				]

				table.render({
					elem: '#wslist-table',
					url: DATA_PATH+"GetWholesaleClientsList",
					page: true,
					cols: cols,
					skin: 'line',
					toolbar: '#wslist-toolbar',
					defaultToolbar: []
				});

				table.on('tool(wslist-table)', function(obj) {
					if (obj.event === 'remove') {
						window.remove(obj);
					} else if (obj.event === 'edit') {
						window.edit(obj);
					}
				});

				table.on('toolbar(wslist-table)', function(obj) {
					if (obj.event === 'add') {
						window.edit(null);
					} else if (obj.event === 'refresh') {
						window.refresh();
					} else if (obj.event === 'batchRemove') {
						window.batchRemove(obj);
					}
				});

				form.on('submit(wslist-query)', function(data) {
					table.reload('wslist-table', {
						where: data.field,
						page:{curr:1}
					})
					return false;
				});
				
				window.edit = function(obj) {
					var _title='添加批发客户';
					var clients_no='';
					var path=MODULE_PATH + 'edit.html'
					if(obj!=null){
							clients_no=obj.data.clients_no;
							_title="编辑批发客户";
							path=MODULE_PATH + 'edit/no/'+clients_no+'.html';
					}
					
					layer.open({
						type: 2,
						title: _title,
						shade: 0.1,
						area: ['850px', '600px'],
						content: path
					});
					
				}
				
				window.batchRemove = function(obj) {
					
					var checkIds = common.checkField(obj,'clients_no');
					
					if (checkIds === "") {
						layer.msg("未选中数据", {
							icon: 3,
							time: 1000
						});
						return false;
					}
					
					layer.confirm('确定要删除这些批发客户?', {
						icon: 3,
						title: '提示'
					}, function(index) {
						layer.close(index);
						let loading = layer.load();
						$.ajax({
							url: MODULE_PATH + "batchDelete/clientsno/" + checkIds,
							dataType: 'json',
							type: 'delete',
							success: function(result) {
								layer.close(loading);
								if (result.code) {
									layer.msg(result.msg, {
										icon: 1,
										time: 1000
									}, function() {
										table.reload('wslist-table');
									});
								} else {
									layer.msg(result.msg, {
										icon: 2,
										time: 1000
									});
								}
							}
						})
					});
				}
				
				window.refresh = function(param) {
					table.reload('wslist-table');
				}
			})
		</script>
	</body>
</html>
